<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta content="IE=9; IE=8; IE=7; IE=EDGE" http-equiv="X-UA-Compatible">
    <meta content="IE=EmulateIE7" http-equiv="X-UA-Compatible"/>
    <title>乐优商城--购物车页面</title>

    <link href="css/webbase.css" rel="stylesheet" type="text/css"/>
    <link href="css/pages-cart.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<div id="cartApp">

    <div class="top">
        <shortcut/>
    </div>

    <div class="cart py-container">

        <!--logoArea-->
        <div class="logoArea">
            <div class="fl logo"><span class="title">购物车</span></div>
        </div>

        <!--All goods-->
        <div class="allgoods">
            <h4>全部商品<span>{{total}}</span></h4>
            <div class="cart-main">
                <div class="yui3-g cart-th">
                    <div class="yui3-u-1-4"><input type="checkbox" v-model="check" @click="checkAll()"/> 全部</div>
                    <div class="yui3-u-1-4">商品</div>
                    <div class="yui3-u-1-8">单价（元）</div>
                    <div class="yui3-u-1-8">数量</div>
                    <div class="yui3-u-1-8">小计（元）</div>
                    <div class="yui3-u-1-8">操作</div>
                </div>
                <div class="cart-item-list">

                    <div class="cart-body">
                        <div class="cart-list">
                            <ul class="goods-list yui3-g" v-for="(cart,index) in carts" :key="index">
                                <li class="yui3-u-1-24">
                                    <input name="" type="checkbox" v-model="selected" :value="cart"/>
                                </li>
                                <li class="yui3-u-11-24">
                                    <div class="good-item">
                                        <div class="item-img"><img height="80px" :src="cart.image" width="80px"/>
                                        </div>
                                        <div class="item-msg">
												<span style="line-height:70px ">
													{{cart.title}}
												</span>
                                            <span v-for="(val,key,index) in JSON.parse(cart.ownSpec)">{{val+" "}}</span>
                                        </div>
                                    </div>
                                </li>

                                <li class="yui3-u-1-8"><span class="price" style="line-height:70px ">{{ly.formatPrice(cart.price)}}</span>
                                </li>
                                <li class="yui3-u-1-8" style="padding-top: 20px">
                                    <a class="increment mins" href="javascript:void(0)" @click="decr(cart)">-</a>
                                    <input autocomplete="off" class="itxt" v-model="cart.num" minnum="1" type="text"
                                           value="1"/>
                                    <a class="increment plus" href="javascript:void(0)" @click="incr(cart)">+</a>
                                </li>
                                <li class="yui3-u-1-8"><span class="sum" style="line-height:70px ">{{cart.price*cart.num}}</span>
                                </li>
                                <li class="yui3-u-1-8">
                                    <a href="javascript:void(0);" @click="deleteCart(index)">删除</a><br/>
                                    <a href="#none">移到我的关注</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

            </div>
            <div class="cart-tool">
                <div class="select-all">
                    <input id="" name="" type="checkbox" value="" v-model="check" @click="checkAll()"/>
                    <span>全选</span>
                </div>
                <div class="option">
                    <a href="#" @click="deleteCart(index)">删除选中的商品</a>
                    <a href="#none">移到我的关注</a>
                    <a href="#none">清除下柜商品</a>
                </div>
                <div class="toolbar">
                    <div class="chosed">已选择<span>{{total}}</span>件商品</div>
                    <div class="sumprice">
                        <span><em>总价（不含运费） ：</em><i class="summoney">{{ly.formatPrice(totalPrice)}}</i></span>
                    </div>
                    <div class="sumbtn">
                        <a class="sum-btn" href="javascript:void(0)" @click="toOrder">结算</a>
                    </div>
                </div>
            </div>

            <div class="liked">
                <ul class="sui-nav nav-tabs">
                    <li class="active">
                        <a data-toggle="tab" href="#index">猜你喜欢</a>
                    </li>
                    <li>
                        <a data-toggle="tab" href="#profile">特惠换购</a>
                    </li>
                </ul>
                <div class="clearfix"></div>
                <div class="tab-content">
                    <div class="tab-pane active" id="index">
                        <div class="sui-carousel slide" data-interval="4000" data-ride="carousel" id="myCarousel">
                            <div class="carousel-inner">
                                <div class="active item">
                                    <ul>
                                        <li>
                                            <img src="img/like1.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like2.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like3.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like4.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <div class="item">
                                    <ul>
                                        <li>
                                            <img src="img/like1.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like2.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like3.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                        <li>
                                            <img src="img/like4.png"/>
                                            <div class="intro">
                                                <i>Apple苹果iPhone 6s (A1699)</i>
                                            </div>
                                            <div class="money">
                                                <span>$29.00</span>
                                            </div>
                                            <div class="incar">
                                                <a class="sui-btn btn-bordered btn-xlarge btn-default" href="#"><i
                                                        class="car"></i><span class="cartxt">加入购物车</span></a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <a class="carousel-control left" data-slide="prev" href="#myCarousel">‹</a>
                            <a class="carousel-control right" data-slide="next" href="#myCarousel">›</a>
                        </div>
                    </div>
                    <div class="tab-pane" id="profile">
                        <p>特惠选购</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script type="text/javascript">
    var cartVm = new Vue({
        el: "#cartApp",
        data: {
            ly,
            carts: [],
            selected: [],
            check: true
        },
        created() {
            ly.verify().then(res => {
                ly.http.get("/cart").then(res => {
                    this.carts = res.data;
                    this.selected = this.carts;
                })
            }).catch(() => {
                this.carts = ly.store.get("LY_CART");
                this.selected = this.carts;
            });
        },
        computed: {
            total() {
                return this.selected.reduce((c1, c2) => c1 + c2.num, 0);
            },
            totalPrice() {
                return this.selected.reduce((c1, c2) => c1 + c2.num * c2.price, 0)
            }
        },
        methods: {
            toOrder() {
                ly.verify().then(res => {
                    ly.store.set("LY_SELECTED", this.selected);
                    window.location = "http://www.leyou.com/getOrderInfo.html"
                }).catch(() => {
                    window.location = "http://www.leyou.com/login.html?returnUrl=http://www.leyou.com/cart.html"
                });
            },
            incr(cart) {
                cart.num++;
                ly.verify().then(res => {
                    ly.http.put("/cart", {skuId: cart.skuId, num: cart.num})
                }).catch(() => {
                    ly.store.set("LY_CART", this.carts)
                });
            },
            decr(cart) {
                if (cart.num > 1) {
                    cart.num--;
                }
                ly.verify().then(res => {
                    ly.http.put("/cart", {skuId: cart.skuId, num: cart.num})
                }).catch(() => {
                    ly.store.set("LY_CART", this.carts)
                });
            },
            deleteCart(index) {
                ly.verify().then(res => {
                    const id = this.carts[index].skuId;
                    this.carts.splice(index, 1);
                    ly.http.delete("/cart/" + id)
                }).catch(() => {
                    this.carts.splice(index, 1);
                    ly.store.set("LY_CART", this.carts)
                });
            },
            checkAll() {
                if (!this.check) {
                    this.selected = this.carts;
                } else {
                    this.selected = [];
                }
            }
        },
        components: {
            shortcut: () => import("/js/pages/shortcut.js")
        }
    })
</script>
<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<script src="js/plugins/jquery/jquery.min.js" type="text/javascript"></script>
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->
<script src="js/plugins/jquery.easing/jquery.easing.min.js" type="text/javascript"></script>
<script src="js/plugins/sui/sui.min.js" type="text/javascript"></script>
<script src="js/widget/nav.js" type="text/javascript"></script>

</body>

</html>